﻿using System;
using System.Diagnostics;
using System.Threading;
using ThrottledProcessing.SampleApplication.Interfaces;

namespace ThrottledProcessing.SampleApplication.Services
{
    public class ConsoleLoggingService : ILoggingService
    {
        public void Debug(string message)
        {
            WriteMessage("Debug", message);
        }

        public void Info(string message)
        {
            WriteMessage("Info", message);
        }

        public void Error(string message)
        {
            WriteMessage("Error", message);
        }

        private void WriteMessage(string level, string message)
        {
            var type = (new StackTrace()).GetFrame(2).GetMethod().DeclaringType.Name;
            Console.WriteLine(string.Format("[{0}] [{1}] [{2}] {3}", level, Thread.CurrentThread.ManagedThreadId, type,
                                            message));
        }
    }
}